package com.lius.SpringBootStart.service.impl;

import com.lius.SpringBootStart.domain.User;
import com.lius.SpringBootStart.domain.Video;
import com.lius.SpringBootStart.mapper.UserMapper;
import com.lius.SpringBootStart.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class UserServiceImpl implements UserService {

    private static Map<String, User> sessionMap = new HashMap<>();

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getUser() {
        List<User> users = new ArrayList<>();

        users.addAll(sessionMap.values());
        return users;
    }

    @Override
    public String login(String account, String passwd) {
        User user = userMapper.login(account, passwd);
        String token = null;
        if (user != null) {
            token = UUID.randomUUID().toString();
            //System.out.println("新增用户"+ user.toString() + "token:" +token);
            sessionMap.put(token, user);
        }
        return token;
    }

    public User getUserByToekn(String token){
        return sessionMap.get(token);
    }
}
